package net.huashitong.scheduling.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sirdc.modules.core.dao.BaseDao;
import com.sirdc.modules.sys.base.StringPKService;
import com.sirdc.modules.utils.ObjectUtils;

import net.huashitong.scheduling.dao.IndustryRevenueDao;
import net.huashitong.scheduling.entity.IndustryRevenue;
import net.huashitong.scheduling.web.RevenueController;
@Service
public class IndustryRevenueService extends StringPKService<IndustryRevenue>{
	
	@Autowired
	private IndustryRevenueDao dao;
	public static final String[] months = {"12","11","10","09","08","07","06","05","04","03","02","01"};
	public static final String[] years={"2018","2017"};
	
	@Override
	protected BaseDao<IndustryRevenue, String> getDao(){
		return dao;
	}
	public IndustryRevenue queryByName(String name,String month,String year){
		return dao.queryByName(name,month,year);
	}
	
	public List<IndustryRevenue> queryBySysId(String sysId){
		return dao.queryBySysId(sysId);
	}
	
	public List<Map<String, Object>> queryIndustryRevenueList(){
		List<Map<String, Object>> RevenueIncomeComplete = new ArrayList<>();
		IndustryRevenue ir=new IndustryRevenue();
		for(int j=0;j<IndustryRevenueService.years.length;j++){
		  	   for(int i=0; i<IndustryRevenueService.months.length;i++){
		  		 ir=dao.queryByName("合计",months[i],years[j]);
		  		if(ObjectUtils.isNotBlank(ir)){
		  			break;
		        }
		  	   }
		}
		List<IndustryRevenue> irlist=dao.queryBySysId(ir.getSysId());
		for(IndustryRevenue irss:irlist){
			Map<String, Object> map3 = new HashMap<String, Object>();
			map3.put("name",irss.getName());
			map3.put("currentYear", irss.getYearIncome());
	    	map3.put("lastYear", irss.getLastyearIncome());
	    	map3.put("increDecre", irss.getIncreDecre());
	    	map3.put("totalRatio", irss.getTotalRatio());
	    	map3.put("units", irss.getUnits());
	    	List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
	    	List<IndustryRevenue> irlist2=dao.queryBySysId(irss.getSysId());
	    	for(IndustryRevenue irss2:irlist2){
	    		Map<String, Object> map4 = new HashMap<String, Object>();
	    		map4.put("name",irss2.getName());
	    		map4.put("currentYear",  irss2.getYearIncome());
	        	map4.put("lastYear",  irss2.getLastyearIncome());
	        	map4.put("increDecre",  irss2.getIncreDecre());
	        	map4.put("totalRatio",  irss2.getTotalRatio());
	        	map4.put("units", irss2.getUnits());
	        	list.add(map4);
	    	}
	    	map3.put("lists", list);
	    	RevenueIncomeComplete.add(map3);
	    }
		return RevenueIncomeComplete;
	}
	
}
